/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file user_idm_client_defines.h
 *
 * @brief Type definitions used by idm client.
 * @since 3.1
 * @version 3.2
 */

#ifndef USER_IDM_CLIENT_DEFINES_H
#define USER_IDM_CLIENT_DEFINES_H

#include <optional>
#include <vector>

#include "iam_common_defines.h"

namespace OHOS {
namespace UserIam {
namespace UserAuth {
/**
 * @brief User credential infomation returned.
 */
struct CredentialInfo {
    /* Auth type supported by executor. */
    AuthType authType {0};
    /* Auth subtype of PIN. */
    std::optional<PinSubType> pinType {};
    /* User credentialId is generated by idm to associate userId and templateId. */
    uint64_t credentialId {0};
    /* User templateId is generated by executor to represent user characteristics. */
    uint64_t templateId {0};
    /* Abandoned flag of pin credential. */
    bool isAbandoned {false};
    /* Valid period of credential remain. */
    int64_t validityPeriod {0};
};

/**
 * @brief Define credential enrollment information.
 */
struct EnrolledInfo {
    /** Auth type supported by executor. */
    AuthType authType {0};
    /** Enrolled ID. */
    uint64_t enrolledId {0};
};

/**
 * @brief Define security user information.
 */
struct SecUserInfo {
    /** Security user ID. */
    uint64_t secureUid {0};
    /** The user credential enrollment infomation. */
    std::vector<EnrolledInfo> enrolledInfo {};
};

/**
 * @brief Parameters needed to set about user credential information.
 */
struct CredentialParameters {
    /** Auth type supported by executor. */
    AuthType authType {0};
    /** Auth subtype of PIN. */
    std::optional<PinSubType> pinType {};
    /** Auth token. */
    std::vector<uint8_t> token {};
};

/**
 * @brief Cred change event type.
 */
enum CredChangeEventType : int32_t {
    /** Cred change type is invalid. */
    INVALID_EVENT_TYPE = -1,
    /** Cred change type is add credential. */
    ADD_CRED = 1,
    /** Cred change type is update credential. */
    UPDATE_CRED = 2,
    /** Cred change type is delete credential. */
    DEL_CRED = 3,
    /** Cred change type is delete user. */
    DEL_USER = 4,
    /** Cred change type is enforce delete user. */
    ENFORCE_DEL_USER = 5,
};

/**
 * @brief Cred change info for notify event.
 */
struct CredChangeEventInfo {
    /** The callerName who make cred change. */
    std::string callerName;
    /** The callerType who make cred change. */
    int32_t callerType;
    /** New credentialId when ADD_CRED or UPDATE_CRED. */
    uint64_t credentialId {0};
    /** Deleted credentialId when DEL_CRED or UPDATE_CRED. */
    uint64_t lastCredentialId {0};
    /** Is silent cred change. */
    bool isSilentCredChange {false};
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

#endif // USER_IDM_CLIENT_DEFINES_H